<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="UTF-8"/>
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <title>秀几种CSS背景渐变图片transtion过渡效果技巧</title>
        <style>
        .box {
            max-width: 400px;
            height: 200px;
            background: linear-gradient(to right, olive, green, purple);
            background-size: 200%;
            transition: background-position .5s;    
        }
        .box:hover {
            background-position: 100% 0;    
        }
        .box1 {
            max-width: 400px;
            height: 200px;
            background: olive linear-gradient(to right, rgba(0,255,0,0), rgba(0,255,0,.5));
            transition: background-color .5s;    
        }
        .box1:hover {
            background-color: purple;    
        }
        .box2 {
            max-width: 400px; height: 200px;
            background: linear-gradient(to right, olive, green);
            position: relative;
            z-index: 0;    
        }
        .box2::before {
            content: '';
            position: absolute;
            left: 0; top: 0; right: 0; bottom: 0;
            background: linear-gradient(to right, green, purple);
            opacity: 0;    
            transition: opacity .5s;
            z-index: -1;
        }
        .box2:hover::before {
            opacity: 1;    
        }
        </style>
    </head>
    <body>
        <h1>秀几种CSS背景渐变图片transtion过渡效果技巧</h1>
        <p>来源:<a href="http://www.zhangxinxu.com/wordpress/2018/03/background-gradient-transtion/">http://www.zhangxinxu.com/wordpress/2018/03/background-gradient-transtion/</a></p>
        <h2>1.借助background-position实现渐变过渡</h2>
        <div class="box"></div>
        <h2>2.借助background-color实现渐变过渡</h2>
        <div class="box1"></div>
        <h2>3.借助伪元素和opacity实现渐变过渡</h2>
        <div class="box2"></div>
    </body>
</html>